package com.xm2.demo.system.customer.dao;

import com.xm2.demo.model.Complaint;
import com.xm2.demo.model.Form;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.persistence.Table;
import javax.persistence.criteria.CriteriaBuilder;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * @Author
 * @Date 2018/12/16 15:54
 * @Description
 */
@Repository
@Table(name="complaint")
@Qualifier("ComplaintRepository")
public interface ComplaintRepository extends JpaRepository<Complaint,Integer> {

    List<Complaint> findByStatus(String status);

    List<Complaint> findByStatus(String status, Pageable pageable);

    @Query("SELECT f FROM Complaint f WHERE f.date > :startDate and f.date < :stopDate")
    List<Complaint> findByDatePagination(@Param("startDate") Date startDate, @Param("stopDate") Date stopDate);

    @Query(value = "SELECT * FROM complaint WHERE date > :startDate and date < :stopDate LIMIT :startRow,:size",nativeQuery=true)
    List<Complaint> findByDatePaginationLimit(@Param("startDate")Date startDate, @Param("stopDate") Date stopDate, @Param("startRow") Integer startRow, @Param("size") Integer size);
    @Modifying
    @Query("update Complaint c set c.status = :status where c.id = :id")
    Integer updateComplaintStatus(@Param("id") Integer id,@Param("status") String status);
}
